<template>
  <el-dialog class="dia-style" :title="title" :visible.sync="isOpen" width="60%" append-to-body>
    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
      <el-form-item label="标准名称" prop="name">
        <el-input v-model="formData.name" placeholder="请输入标准名称" clearable :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="标准类型" prop="type">
        <el-select v-model="formData.type" placeholder="请输入标准类型" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in typeOptions" :key="index" :label="item.label" :value="item.value"
                     :disabled="item.disabled"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="描述信息" prop="description">
        <el-input v-model="formData.description" type="textarea" placeholder="请输入描述信息" :maxlength="100"
                  :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">保 存</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  components: {},
  props: {
    title: {
      type: String,
      default() {
        return '编辑'
      }
    },
    formData:{
      type:Object,
      default(){
        return {
          name: undefined,
          type: undefined,
          description: undefined
        }
      }
    }
  },
  data() {
    return {
      isOpen:false,
      rules: {
        name: [{
          required: true,
          message: '请输入标准名称',
          trigger: 'blur'
        }],
        type: [{
          required: true,
          message: '请输入标准类型',
          trigger: 'change'
        }],
        description: []
      },
      typeOptions: [{
        'label': 'JSON',
        'value': 1
      }, {
        'label': '二维表',
        'value': 2
      }]
    }
  },
  computed: {},
  watch: {},
  created() {
  },
  mounted() {
  },
  methods: {
    submitForm() {
      this.$refs['elForm'].validate(valid => {
       if(valid){
         this.$modal.msgSuccess('保存成功')
         this.isOpen = false
       }
        // TODO 提交表单
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
    cancel(){
      this.isOpen=false
    }
  }
}

</script>
<style>
</style>
